<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>myproject</title>
    <style>
        div {
            position: relative;
            width: 340px;
            margin: 100px auto;
        }

        .ipt {
            width: 300px;
            height: 20px;
            border: 0px;
            border-bottom: 1px solid #ccc;
        }

        .register img {
            position: absolute;
            width: 24px;
            right: 0px;
            top: 0px;
        }

        .message {
            display: inline-block;
            font-size: 12px;
            color: #999;
            padding-left: 20px;
        }

        .wrong {
            color: crimson;
        }

        .right {
            color: green;
        }
    </style>
</head>

<body>
    <div class="register">
        <input type="password" class="ipt" id="pwd">
        <label for="">
            <img src="00.png" id="eye">
        </label>
        <p class="message">输入6-10位数</p>
    </div>
    <script>
        var eye = document.getElementById('eye');
        var pwd = document.getElementById('pwd');
        var flag = 0;
        eye.onclick = function () {
            if (flag == 0) {
                eye.src = "01.png";
                pwd.type = "text";
                flag = 1;
            } else {
                eye.src = "00.png";
                pwd.type = "password";
                flag = 0;
            }
        }

        var message = document.querySelector('.message');
        /* 当失去焦点（即输入完）的时候判断是否符合要求 */
        pwd.onblur = function () {
            if (pwd.value.length < 6 || pwd.value.length > 10) {
                message.className = 'message wrong';
                message.innerHTML = '位数不对';
            } else {
                message.className = 'message right';
                message.innerHTML = '输入正确';
            }
        }

    </script>
</body>

</html>